<!-- /**
** @descerpion:这是传统的饼图
 */ -->
<template>
  <Echart
    id="centreLeft1Charttwo"
    :options="options"
    :height="nowheight"
    :width="nowwidth"
  />
</template>

<script>
import Echart from "../../baseMain/index.vue";
export default {
  components: {
    Echart
  },
  props: {
    zhtitle: {
      type: String,
      default: () => ""
    },
    nowwidth: {
      type: String,
      default: () => "100%"
    },
    nowheight: {
      type: String,
      default: () => "100%"
    },
    cdata: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      options: {}
    };
  },
  watch: {
    cdata: {
      handler(newData) {
        // console.log(newData);
        this.options = {
          color: [
            "#57d2a3",
            "#eeb91c",
            "#5b8ff9",
            "#32c5e9",
            "#fb7293",
            "#8378ea",
            "#37a2da",
            "#e7bcf3",
            "#ffdb5c",
            "#C33531",
            "#EFE42A",
            "#64BD3D",
            "#EE9201",
            "#29AAE3",
            "#B74AE5",
            "#0AAF9F",
            "#E89589",
            "#16A085",
            "#4A235A",
            "#C39BD3",
            "#F9E79F",
            "#BA4A00",
            "#ECF0F1",
            "#616A6B",
            "#EAF2F8",
            "#4A235A",
            "#3498DB"
          ],
          tooltip: {
            trigger: "item", // 数据项图形触发
            formatter: `{a} <br/>{b}: {c}次 ({d}%)` // 展示格式
          },
          toolbox: {
            show: true
          },
          grid: {
            left: "20",
            right: "20",
            bottom: "20",
            top: "20",
            containLabel: true
          },
          label: {
            normal: {
              show: true,
              // formatter: "{b}\n{d}% ",
              textStyle: {
                color: "#fff"
              }
              // rich: { // 定义不同地方的文字的字体大小和颜色
              //   a: {
              //     color: '#999',
              //     lineHeight: 22,
              //     align: 'center'
              //   },
              //   hr: {
              //     borderColor: '#aaa',
              //     width: '100%',
              //     borderWidth: 0.5,
              //     height: 0
              //   },
              //   b: {
              //     fontSize: 16,
              //     lineHeight: 33,
              //     width: '3px'
              //   },
              //   per: {
              //     color: '#eee',
              //     backgroundColor: '#334455',
              //     padding: [2, 4],
              //     borderRadius: 2
              //   }
              // }
              // formatter: function(v) {
              //   let text = v.name
              //   let d = v.rate
              //   // console.log(v)
              //   return text.length < 4
              //     ? text
              //     : `${text.slice(0, 6)}\n${text.slice(6)}\n${d}%`
              // }
            }
          },
          labelLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 1)"
            },
            smooth: 0.2,
            length: 10,
            length2: 20
          },
          legend: {
            show: false,
            orient: "horizontal",
            icon: "circle",
            // bottom: 0,
            x: "center",
            data: newData.xData,
            textStyle: { color: "#FFFDFE" }
          },
          series: newData
        };
        if (this.zhtitle.length > 0) {
          this.options.title = {
            text: this.zhtitle,
            left: "center",
            textStyle: {
              fontSize: 14,
              // fontWeight:"blod",
              color: "#fff"
            }
          };
        }
      },
      immediate: true,
      deep: true
    }
  }
};
</script>

<style lang="scss" scoped></style>
